/**
 * @author Aaron
 * @createTime 18:23 2022/5/27
 **/
package services

import (
	"longmen/server/pkg/common/api_models"
	"longmen/server/pkg/db/mysql/db_main"
	"time"
)

func (s *Service) GetActivityRecord(uid int) ([]*api_models.ActivityRecordRewordResp, error) {
	invite, _ := db_main.GetActivityRecord(uid)
	var ids []int
	var recordTimeMap map[uint8]time.Time
	recordTimeMap = make(map[uint8]time.Time)
	for _, v := range invite {
		ids = append(ids, int(v.ActivityId))
		recordTimeMap[v.ActivityId] = v.CreatedAt
	}
	var resp []*api_models.ActivityRecordRewordResp
	if len(ids) > 0 {
		activitys, err := db_main.GetActivityListByParam(map[string]interface{}{"id": map[string]interface{}{"in": ids}}, "", 0, 0)
		if err != nil {
			return nil, err
		}

		for _, v := range activitys {
			var vs api_models.ActivityRecordRewordResp
			vs.Id = uint64(v.Id)
			vs.Exp = v.Experience
			vs.Diamond = v.Carat
			vs.Gold = v.EagleDrill
			vs.Name = v.Title
			vs.CreateTime = recordTimeMap[uint8(v.Id)].Unix()
			resp = append(resp, &vs)
		}
	}
	return resp, nil
}
